from qiniu import Auth,put_data

# 拼接访问全路径 ： http://oyucyko3w.bkt.clouddn.com/FrmZHVEGylygB5DGuyhcb1i6eOT5
access_key = "yV4GmNBLOgQK-1Sn3o4jktGLFdFSrlywR2C-hvsW"
secret_key = "bixMURPL6tHjrb8QKVg2tm7n9k8C7vaOeQ4MEoeW"
bucket_name = 'ihome'

def upload_file(file_data):
    """实现上传、存储文件到七牛云"""
    q = Auth(access_key,secret_key)
    token = q.upload_token(bucket_name)
    ret,info = put_data(token,None,file_data)
    #print(ret,info)

    if 200 == info.status_code:
        return ret.get('key')
    else:
        raise Exception('上传图片失败')

if __name__ == '__main__':
    path = '/home/python/Desktop/3cba716d00dc5872d8e0ef339870a54c.jpg'
    with open(path, 'rb') as file:
        upload_file(file.read())